<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<script type="text/javascript">
	$(function(){
		$.metadata.setType("attr","validate");
		$("#album_edit_form").validate({
			
			submitHandler: function() {
				
				
				var album = new Album();
				album.identifier=$("#album_id").val();
				album.name = $("#name").val();
				album.description = $("#description").val();
				album.visibility = $("#visibility").val();
				album.place = $("#place").val();
				album.cover=$(":radio[name='cover'][checked]").val();
				album.imageServer=$(":radio[name='cover'][checked]").attr("imageServer");
				var arrayObj = new Array();
				$(".Edit_box").each(function(){
					var index = $(".Edit_box").index(this);
					var photoTitle = $(this).find("#photo_title").val();
					var photoAlbum = $(this).find("#photo_album").val();
					var photoId = $(this).find("#photo_id").val();
					var thumbnail = $(this).find("#photo_thumbnail").val();
					arrayObj.push({
						identifier:photoId,
						title:photoTitle,
						album:photoAlbum,
						thumbnail:thumbnail
					})
				});
				album.pictureList = arrayObj;
				$("#content_detail").load("albumEditSave.htm",{
					album:album.identifier,
					jsonData:escape($.toJSON(album))
				},function(){
					$("#album_info_tip_success").show();
					$("#album_info_tip_success").fadeOut(4000);
				});
				
			}
		});
		
		$("#album_edit_back").click(function(){
			myPhoto();
		});
		
		$(".Edit_box").ImageAutoSize(100,74);
		
	});
	
	function albumEditDelete(album){
		if(confirm("删除专辑，会将专辑中的所有照片都删除。\r\n你确定要删除该专辑吗？")){
			$("#content_detail").load("albumDelete.htm?album="+album);
		}
	}
	
	function deletePhoto(album,photoId,deleteCoverFlag,imageServer){
		if(confirm("你确定要删除该照片吗？")){
			$("#photoContent").load("photoDelete.htm",{
				album:album,
				photoId:photoId,
				deleteCoverFlag:deleteCoverFlag,
				imageServer:imageServer
			},function(){
				$("#base_info_tip_success").show();
				$("#base_info_tip_success").fadeOut(4000);
			});
		}
	}
</script>

<form action="albumEditSave.htm" id="album_edit_form">
	<div class="h_newNews_box">
		<div class="h_newNews_text" id="con_newNews_1" style="display: block;">
			<div class="data_h_newNews_nav">
				<a href="javascript:void(0);" class="current" onclick="albumInfo();">返回照片专辑</a>|<a href="javascript:void(0);" onclick="albumInfoUploadPhoto('${album.identifier}');">添加新照片</a>|<a
					href="javascript:void(0);" id="album_eidt_delete" onclick="albumEditDelete('${album.identifier}');">删除该专辑</a>
			</div>
			<div class="success" id="base_info_tip_success" style="display: none;"><img alt="删除成功" src="images/home_images/ico29.png" />照片删除成功</div>
			
			<div class="clear"></div>
			<div class="photosEdit_box">
				<input type="hidden" value="${album.identifier}" id="album_id"/>
				<h2>专辑信息：</h2>
				<table>
					<tr>
						<td width="43">名称：</td>
						<td width="229"><input type="text" id="name" value="<c:out value="${album.name}" />" maxlength="50" validate="{required:true,messages:{required:'不能为空'}}" />
						</td>
						<td width="41">描述:</td>
						<td width="257" rowspan="2"><textarea name="" id="description" cols="" rows="" validate="{maxlength:800}"><c:out value="${album.description}" /></textarea>
						</td>
					</tr>
					<tr>
						<td>地点：</td>
						<td><input type="text" id="place" value="<c:out value="${album.place}"  />" validate="{maxlength:90}" maxlength="100"/>
						</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>权限：</td>
						<td><select name="visibility" id="visibility">
								<option value="02" 
								<c:if test="${album.visibility=='02'}">
									SELECTED
								</c:if>
								>仅邻居</option>
								<option value="01"
								<c:if test="${album.visibility=='01'}">
									SELECTED
								</c:if>
								>任何人可见</option>
						</select></td>
						<td>&nbsp;</td>
					</tr>
				</table>

			</div>
		</div>
		<div class="photosEdit_newsort">
			<h2>专辑信息：</h2>
			<c:forEach items="${photoList}" var="photo">
				<div class="Edit_box">
					<input type="hidden" value="${photo.identifier}" id="photo_id"/>
					<table>
						<tr>
							<td width="107" rowspan="3">
								<input type="hidden" value="${photo.thumbnail}" id="photo_thumbnail"/>
								<div style="text-align: center;"><img  src="${photo.imageServer}${photo.thumbnail}" alt="图片" /></div>
							</td>
							<td width="52">照片名：</td>
							<td width="143"><input type="text" id="photo_title" class="photosEdit_name" value="<c:out value="${photo.title}" />" />
							</td>
						</tr>
						<tr>
							<td>转移到：</td>
							<td><select name="" id="photo_album">
								<c:forEach items="${albumList}" var="albumTmp">
									<option value="${albumTmp.identifier}"
									<c:if test="${album.identifier==albumTmp.identifier}">
										SELECTED
									</c:if>
									><c:out value="${albumTmp.name}" /></option>
								</c:forEach>
							</select></td>
						</tr>
						<tr>
							<td>&nbsp;</td>
							<td><input name="cover" type="radio" value="${photo.thumbnail}" imageServer="${photo.imageServer}"
							<c:if test="${album.cover==photo.thumbnail}">checked="checked"</c:if>
							 />设为该专辑封面</td>
						</tr>
					</table>
						
					<div class="Edit_delete" 
						
					<c:choose>
						<c:when test="${album.cover==photo.thumbnail}">
							onclick="deletePhoto('${album.identifier}','${photo.identifier}',true,'${photo.imageServer}');"
						</c:when>
						<c:otherwise>
							onclick="deletePhoto('${album.identifier}','${photo.identifier}',false,'${photo.imageServer}');"
						</c:otherwise>
					</c:choose>
					>
						<img src="images/home_images/delete.gif" alt="删除" />
					</div>
				</div>
				
			</c:forEach>
			

			
			<div class="clear"></div>
			
		</div>
		<div class="h_button w75 fl mr5" onclick="$('#album_edit_form').submit();"><strong>保存设置</strong></div>
		
		<div class="h_button fl" onclick="albumInfo();"><strong>取 消</strong></div>
		
		<div class="h_newNews_text" id="con_newNews_2">fdsfsdf</div>
	</div>
</form>

